home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-06 | 6.6 KB | 369 lines | [TEXT/CWIE] |
- // Stuff.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "DDocData.h"
- #include "EverythingEngine.h"
- #include "EverythingDoc.h"
-
- #include "Stuff.h"
-
-
- //----------
- void Stuff::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- Stuff* winObj = new Stuff;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- Stuff::Stuff ()
- {
- mData = nil;
- }
-
- //----------
- Stuff::~Stuff ()
- {
- }
-
- //----------
- EverythingEngine* Stuff::GetEngine ()
- {
- return (EverythingEngine*) mDoc->mEngine;
- }
-
- //----------
- void Stuff::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_Stuff, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((EverythingDoc*)mDoc)->mStuffPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_Stuff);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mToolsHandle = ::GetNewControl (CNTL_Tools, window);
- SetWindowItemFont (mToolsHandle, wftb, 1);
-
-
- mPopupsHandle = ::GetNewControl (CNTL_Popups, window);
- SetWindowItemFont (mPopupsHandle, wftb, 2);
-
- mFromValuesList2Handle = ::GetNewControl (CNTL_FromValuesList2, window);
- EmbedControl (mFromValuesList2Handle, mPopupsHandle);
- SetWindowItemFont (mFromValuesList2Handle, wftb, 3);
-
- mFromMenuHandle = ::GetNewControl (CNTL_FromMenu, window);
- EmbedControl (mFromMenuHandle, mPopupsHandle);
- SetWindowItemFont (mFromMenuHandle, wftb, 4);
-
-
- mListsHandle = ::GetNewControl (CNTL_Lists, window);
- SetWindowItemFont (mListsHandle, wftb, 5);
-
- mTextListHandle = ::GetNewControl (CNTL_TextList, window);
- EmbedControl (mTextListHandle, mListsHandle);
- SetWindowItemFont (mTextListHandle, wftb, 6);
- BuildTextListList (mTextListHandle);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void Stuff::Close ()
- {
- mData->RemoveResponder (this);
-
- ((EverythingDoc*)mDoc)->mStuffPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void Stuff::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- SetControlValue (mToolsHandle, mData->GetTools ());
- SetControlValue (mFromValuesList2Handle, mData->GetFromValuesList2 ());
- SetControlValue (mFromMenuHandle, mData->GetFromMenu ());
- SetListBoxChoice (mTextListHandle, mData->GetTextList ());
- }
-
- //----------
- void Stuff::DataChanged (
- long inDataID)
- {
- if (inDataID == idTools) {
- SetControlValue (mToolsHandle, mData->GetTools ());
- }
- if (inDataID == idFromValuesList2) {
- SetControlValue (mFromValuesList2Handle, mData->GetFromValuesList2 ());
- }
- if (inDataID == idFromMenu) {
- SetControlValue (mFromMenuHandle, mData->GetFromMenu ());
- }
- }
-
- //----------
- void Stuff::BuildTextListList (
- ControlHandle inControl)
- {
- ListHandle list = GetListHandle (inControl);
-
- AddToList ("\pOne", list);
- AddToList ("\pTwo", list);
- AddToList ("\pThree", list);
- AddToList ("\pInfinity", list);
- }
-
- //----------
- void Stuff::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mToolsHandle) {
- if (TrackClick (mToolsHandle, where) != 0) {
- mData->SetTools (GetControlValue (mToolsHandle));
- }
- }
- if (whichControl == mFromValuesList2Handle) {
- if (TrackClick (mFromValuesList2Handle, where) != 0) {
- mData->SetFromValuesList2 (GetControlValue (mFromValuesList2Handle));
- }
- }
- if (whichControl == mFromMenuHandle) {
- if (TrackClick (mFromMenuHandle, where) != 0) {
- mData->SetFromMenu (GetControlValue (mFromMenuHandle));
- }
- }
- if (whichControl == mTextListHandle) {
- if (TrackClick (mTextListHandle, where)) {
- if (WasDoubleClick (mTextListHandle)) {
- } else { // single click
- mData->SetTextList (GetListBoxChoice (mTextListHandle));
- }
- }
- }
- }
-
- //----------
- void Stuff::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void Stuff::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- //----------
- void Stuff::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void Stuff::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void Stuff::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void Stuff::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void Stuff::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void Stuff::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void Stuff::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void Stuff::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void Stuff::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void Stuff::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- Boolean Stuff::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-